package offer.offer21;

/**
 * @Author: wjy
 * @Date: 2021/10/26 15:39
 */
public class Solution {

    public static void main(String[] args) {

        int[] nums = {1,2,3,4};

        Solution solution = new Solution();
        int[] exchange = solution.exchange(nums);

        for (int i : exchange) {
            System.out.println(i);
        }

    }

    public int[] exchange(int[] nums) {

        int left = 0;
        int right =nums.length - 1;
        int[] res = new int[nums.length];

        for (int i = 0; i < nums.length; i++) {

            if (nums[i] % 2 != 0) {
                res[left++] = nums[i];
            }
            if (nums[i] % 2 == 0) {
                res[right--] = nums[i];
            }

        }
        return res;

    }

}
